package com.neudu.yiyang.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neudu.yiyang.commons.JSONReturn;
import com.neudu.yiyang.pojo.Customer;
import com.neudu.yiyang.pojo.Nurselevel;
import com.neudu.yiyang.service.NurselevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class NurselevelController {
    @Autowired
    private NurselevelService nurselevelService;
    @Autowired
    private JSONReturn jsonReturn;
    @RequestMapping("get_all_nurselevel")
    public String getAll(){
        try {
            List<Nurselevel> list = nurselevelService.list();
            return jsonReturn.returnSuccess(list);
        } catch (Exception e) {
            e.printStackTrace();
            return jsonReturn.returnError(e.getMessage());
        }
    }
    @RequestMapping("get_nurseLevel_by")
    public String getByCondition(Nurselevel nurselevel){
        try {
            LambdaQueryWrapper<Nurselevel> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(!ObjectUtils.isEmpty(nurselevel.getId()), Nurselevel::getId, nurselevel.getId())
                    .eq(!ObjectUtils.isEmpty(nurselevel.getLevelName()), Nurselevel::getLevelName, nurselevel.getLevelName())
                    .eq(!ObjectUtils.isEmpty(nurselevel.getLevelStatus()), Nurselevel::getLevelStatus, nurselevel.getLevelStatus());
            List<Nurselevel> nurselevels = nurselevelService.list(queryWrapper);
            return jsonReturn.returnSuccess(nurselevels);
        } catch (Exception e) {
            e.printStackTrace();
            return jsonReturn.returnError(e.getMessage());
        }
    }
    @RequestMapping("add_one_level")
    public String addOne(@RequestBody Nurselevel nurselevel){
        try {
            nurselevelService.save(nurselevel);
            return jsonReturn.returnSuccess();
        } catch (Exception e) {
            e.printStackTrace();
            return jsonReturn.returnError(e.getMessage());
        }
    }
    @RequestMapping("getlevelby_id")
    public String getById(@RequestParam("levelid") Integer levelid){
        try {
            Nurselevel nurselevel = nurselevelService.getById(levelid);
            return jsonReturn.returnSuccess(nurselevel);
        } catch (Exception e) {
            e.printStackTrace();
            return jsonReturn.returnError(e.getMessage());
        }
    }
    @RequestMapping("modifylevelby_id")
    public String modifyById(@RequestBody Nurselevel nurselevel){
        try {
            nurselevelService.updateById(nurselevel);
            return jsonReturn.returnSuccess(nurselevel);
        } catch (Exception e) {
            e.printStackTrace();
            return jsonReturn.returnError(e.getMessage());
        }
    }
    @RequestMapping("removelevel_by_id")
    public String removeByid(@RequestParam("levelid") Integer levelid) {
        try {
            nurselevelService.removeById(levelid);
            return jsonReturn.returnSuccess();
        } catch (Exception e) {
            e.printStackTrace();
            return jsonReturn.returnError(e.getMessage());
        }
    }
}
